<%@ page language="java" import="java.util.List" pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
	<head>
		<html:base />
    
		<title>Search Topic</title>
		<link href="login.css" rel="stylesheet" type="text/css">
	</head>
  
	<body>
    	<logic:notPresent name="topics" scope="session">
			<logic:redirect page="/illegal_access.jsp"></logic:redirect>
		</logic:notPresent>
		<logic:notPresent name="page" scope="session">
			<logic:redirect page="/illegal_access.jsp"></logic:redirect>
		</logic:notPresent>
    	<% 
			int current_offset=(Integer) session.getAttribute("page");
			int list_size=((List) session.getAttribute("topics")).size();
			int current_end=current_offset+10;
			pageContext.setAttribute("co", current_offset);
		 %>
		<div class="container">
			<div class="header">
				<html:img page="/yssz.jpg"/>
				<div id="login">
					<html:link action="mainPre">main page</html:link>
					<html:link page="/form/search.jsp">back to search engine</html:link>
				</div>
			</div>
			<div class="content">
				<h1>Search Topic</h1>
					<table width="800" border="1" cellspacing="0" cellpadding="0">
						<tr align="center" valign="middle">
							<td>话题</td>
							<td>话题组</td>
							<td>发布者</td>
							<td>发布日期</td>
							<logic:present name="admin" scope="session">
								<td>&nbsp;</td>
							</logic:present>
						</tr>
						<logic:iterate id="topicList" name="topics" scope="session" length="10" offset="co">
							<tr align="center" valign="middle">
								<bean:define id="topic_id" name="topicList" property="id"></bean:define>
								<td><a href="/se3/prePoster.do?topicid=<%=topic_id  %>"><bean:write name="topicList" property="name"/></a></td>
								<td><bean:write name="topicList" property="group"/></td>
								<td><bean:write name="topicList" property="topic_creater"/></td>
								<td><bean:write name="topicList" property="topic_create_time"/></td>
								<logic:present name="admin" scope="session">
									<td><a href="/se3/deleteTopic.do?topicid=<%=topic_id %>">delete</a></td>
								</logic:present>
							</tr>
						</logic:iterate>
						<% 
							boolean have=false;
							if(current_offset!=0) {
								out.write("<tr><td colspan=\"4\" align=\"right\"><a href=\"/se3/firstPage.do?from=search_topic\">首页</a> ");
								out.write("<a href=\"/se3/previewPage.do?from=search_topic\">上一页</a> ");
								have=true;
							}
							if(current_end<list_size) {
								if(!have) {
									out.write("<tr><td colspan=\"4\" align=\"right\">");
								}
								out.write("<a href=\"/se3/nextPage.do?from=search_topic\">下一页</a> ");
								out.write("<a href=\"/se3/lastPage.do?from=search_topic&size="+list_size+"\">末页</a></td></tr>");	
							}
							else {
								out.write("</td></tr>");
							}
						%>
					</table>
			</div>
			<div class="footer">
				<p>copyright@yssz</p>
			</div>
		</div>
  </body>
</html:html>
